package com.augmentum.oes.common;

import java.util.HashMap;
import java.util.Map;

public class AppContext {
    private static ThreadLocal<AppContext> appContextMap = new ThreadLocal<AppContext>();
    private Map<String, Object> data = new HashMap<>();

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public void addData(String key, Object value) {
        data.put(key, value);
    }

    public Object getData(String key) {
        return data.get(key);
    }

    public Object removeData(String key) {
        return data.remove(key);
    }

    public void clear() {
        data.clear();
    }

    private AppContext() {
    }

    public static AppContext getInstance() {
        AppContext appContext = appContextMap.get();
        if (appContext == null) {
            appContext = new AppContext();
            appContextMap.set(appContext);
        }
        return appContext;
    }
}
